package org.example.secondkill.dao;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.example.secondkill.domain.Goods;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 主要对strategy秒杀策略表进行操作
 */
@Mapper
@Repository
public interface GoodsDao {
    // 查询所有待秒杀的商品
    @Select("select g.id, g.goods_name, g.goods_price, g.goods_stock, g.start_date, g.end_date from t_good g;")
    List<Goods> selectAllGoods();

    // 查询指定id的商品
    @Select("select g.id, g.goods_name, g.goods_price, g.goods_stock, g.start_date, g.end_date from t_good g where g.id=#{goodsId}")
    Goods selectGoodsVOByGoodsId(@Param("goodsId") long goodsId);

    // 重新设置库存
    @Update("update t_good set goods_stock = #{goodsStock} where id =#{id}")
    void updateStock(Goods goods);
}
